//
//  UIBarButtonItem+Extensions.swift
//  MyWeibo
//
//  Created by timw on 2017/3/20.
//  Copyright © 2017年 wuqc. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize，默认16号
    ///   - action: action
    ///   - target: target
    ///   - isBack: 是否是返回按钮，如果是，加< ,默认false
    ///
    /// - returns: UIBarButtonItem
    
    convenience init(title: String, fontSize: CGFloat = 16, target:Any?, action: Selector, isBack: Bool = false) {
    
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        // self.init 实力化 UIBarButtonItem
        self.init(customView: btn)
    }
}
